package Chapter2.Comparing.c6;

import java.util.*;

public class MapDemo3 {
    public static void main(String[] args) {
        User u1 = new User("Tom1",12);
        User u2 = new User("Tom2",16);
        User u3 = new User("Tom4",13);
        User u4 = new User("Tom3",11);
        List<User> users1 = new ArrayList<>();
        users1.add(u1);
        users1.add(u2);
        List<User> users2 = new ArrayList<>();
        users2.add(u3);
        users2.add(u4);

        Map<String,Object> map1 = new LinkedHashMap<>();
        map1.put("name","gamer");
        map1.put("size",users1.size());
        map1.put("list",users1);

        Map<String,Object> map2 = new LinkedHashMap<>();
        map2.put("name","musician");
        map2.put("size",users2.size());
        map2.put("list",users2);

        /*Set<String> keys = map1.keySet();
        Collection<Object> values = map1.values();*/

        List<Map<String, Object>> usersAll = new ArrayList<>();
        usersAll.add(map1);
        usersAll.add(map2);

        for(Map<String, Object> map:usersAll){
            for (Map.Entry set:map.entrySet()){
                System.out.println(set.getKey()+":"+set.getValue());
            }
            System.out.println("----------------------");
        }

        for(Map<String,Object> map:usersAll) {
            for(Map.Entry set: map.entrySet()) {
                Object value = set.getValue();
                if(value instanceof  List) {
                    List<User> users = (List<User>) value;
                    for(User u :users) {
                        System.out.println(u);
                    }
                }
                else {
                    System.out.println(set.getKey()+":"+value);
                }
            }
            System.out.println("----------------------");
        }

    }
}
